Uygulama sürekli duruyor
08.08.2017 - 10:26
Uygulama birkaç kez çalıştı daha sonra sürekli durmaya başladı ve aşağıdaki hatayı aldım.Clean ve rebulti denedim ama düzelmedi.
Logcat
08-08 10:18:14.484 30997-30997/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.tckcakar.myapplication, PID: 30997
java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
at com.example.tckcakar.myapplication.MainActivity$MyAdapter.getView(MainActivity.java:72)
at android.widget.AbsListView.obtainView(AbsListView.java:3238)
at android.widget.GridView.onMeasure(GridView.java:1096)
at android.view.View.measure(View.java:21051)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:21051)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:21051)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459)
at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391)
at android.view.View.measure(View.java:21051)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:21051)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:21051)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:853)
at android.view.View.measure(View.java:21051)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2583)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1642)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1893)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1522)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7098)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
at android.view.Choreographer.doCallbacks(Choreographer.java:702)
at android.view.Choreographer.doFrame(Choreographer.java:638)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
MainActivity.java
package com.example.tckcakar.myapplication;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
GridView gridView;
float ilkdeger = 0;
public double sonuc = 0;
public String islem;
String[] dizi = {
"7", "8", "9", "C", "4", "5", "6", "/", "1", "2", "3", "*", "0", "=", "+", "-"
};
public MainActivity() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = (GridView) findViewById(R.id.gridView1);
ArrayAdapter<String> adapter = new MyAdapter(this);
adapter.addAll(dizi);//diziyi adaptöre gönderdik.
gridView.setAdapter(adapter);//gridview ve adaptörü bağladık.
adapter.notifyDataSetChanged();
Intent intent=new Intent(this,click.class);
startActivity(intent);
}
public void onAttachFragment(Activity activity) {
}
@Override
public void onClick(View view) {
}
private class MyAdapter extends ArrayAdapter<String> {//adaptörü sınıf olarak oluşturduk.
MyAdapter(@NonNull Context context) {
super(context, android.R.layout.simple_list_item_1);
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {// pozisyonunu alır ve çizer
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.calc_button, parent, false);//VİEWVİ GÖRSEL HALE GETİRRİ INFLATER
}
TextView button = (TextView) convertView;
button.setText(getItem(position));//pozisyonu alır.
return button;
}
}
}
click.class
package com.example.tckcakar.myapplication;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;
/**
* Created by TCKCAKAR on 7.8.2017.
*/
public class click extends MainActivity implements View.OnClickListener {
TextView btn0 = (TextView) findViewById(R.id.textView0);
TextView btn1 = (TextView) findViewById(R.id.textbir);
TextView btn2 = (TextView) findViewById(R.id.textViewiki);
TextView btn3 = (TextView) findViewById(R.id.textViewüç);
TextView btn4 = (TextView) findViewById(R.id.textView4);
TextView btn5 = (TextView) findViewById(R.id.textView5);
TextView btn6 = (TextView) findViewById(R.id.textView6);
TextView btn7 = (TextView) findViewById(R.id.textView2);
TextView btn8 = (TextView) findViewById(R.id.textView1);
TextView btn9 = (TextView) findViewById(R.id.textView3);
TextView btnc = (TextView) findViewById(R.id.textViewC);
TextView topla = (TextView) findViewById(R.id.topla);
TextView cıkar = (TextView) findViewById(R.id.cıkar);
TextView carp = (TextView) findViewById(R.id.textViewyıldız);
TextView böl = (TextView) findViewById(R.id.bölme);
TextView sonuç = (TextView) findViewById(R.id.textVieweşit);
TextView edit = (TextView) findViewById(R.id.edit);
{
btn0.setOnClickListener(this);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);
btn4.setOnClickListener(this);
btn5.setOnClickListener(this);
btn6.setOnClickListener(this);
btn7.setOnClickListener(this);
btn8.setOnClickListener(this);
btn9.setOnClickListener(this);
btnc.setOnClickListener(this);
topla.setOnClickListener(this);
cıkar.setOnClickListener(this);
carp.setOnClickListener(this);
böl.setOnClickListener(this);
sonuç.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.textbir:
edit.setText(edit.getText() + "1");
case R.id.textViewiki:
edit.setText(edit.getText() + "2");
case R.id.textViewüç:
edit.setText(edit.getText() + "3");
case R.id.textView4:
edit.setText(edit.getText() + "4");
case R.id.textView5:
edit.setText(edit.getText() + "5");
case R.id.textView6:
edit.setText(edit.getText() + "6");
case R.id.textView7:
edit.setText(edit.getText() + "7");
case R.id.textView8:
edit.setText(edit.getText() + "8");
case R.id.textView3:
edit.setText(edit.getText() + "9");
case R.id.textViewC:
try {
ilkdeger = 0;
sonuc = 0;
edit.setText("");
} catch (Exception btnC) {
}
case R.id.topla:
try {
if (!edit.getText().toString().isEmpty()) {
ilkdeger = Float.parseFloat(edit.getText().toString());
edit.setText("");
islem = "Toplama";
}
} catch (Exception C) {
}
case R.id.cıkar:
try {
if (!edit.getText().toString().isEmpty()) {
ilkdeger = Float.parseFloat(edit.getText().toString());
edit.setText("");
islem = "Çıkarma";
}
} catch (Exception C) {
}
case R.id.textViewyıldız:
try {
if (!edit.getText().toString().isEmpty()) {
ilkdeger = Float.parseFloat(edit.getText().toString());
edit.setText("");
islem = "Çarpma";
}
} catch (Exception C) {
}
case R.id.bölme:
try {
if (!edit.getText().toString().isEmpty()) {
ilkdeger = Float.parseFloat(edit.getText().toString());
edit.setText("");
islem = "Bölme";
}
} catch (Exception C) {
}
case R.id.textVieweşit:
if (!edit.getText().toString().isEmpty() && !String.valueOf(ilkdeger).equals("0")) {
if (islem.equals("Toplama")) {
sonuc = ilkdeger + Float.parseFloat(edit.getText().toString());
} else if (islem.equals("Çıkarma")) {
sonuc = ilkdeger - Float.parseFloat(edit.getText().toString());
} else if (islem.equals("Çarpma")) {
sonuc = ilkdeger * Float.parseFloat(edit.getText().toString());
} else if (islem.equals("Bölme")) {
sonuc = ilkdeger / Float.parseFloat(edit.getText().toString());
}
edit.setText(String.valueOf(sonuc));
ilkdeger = 0;
sonuc = 0;
} else {
edit.setText("Değer giriniz");
}
if (R.id.textViewC == v.getId()
) {
ilkdeger = 0;
sonuc = 0;
edit.setText("");
}
}
}
}
activy_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.tckcakar.myapplication.MainActivity">
<TextView
android:layout_width="0dp"
android:layout_height="495dp"
tools:layout_editor_absoluteY="-265dp"
tools:layout_editor_absoluteX="98dp"
android:id="@+id/edit"/>
<GridView
android:id="@+id/gridView1"
android:layout_width="82dp"
android:layout_height="495dp"
android:columnWidth="50dp"
android:gravity="center"
android:numColumns="4"
tools:layout_editor_absoluteX="122dp"
tools:layout_editor_absoluteY="60dp">
</GridView>
</RelativeLayout>
calc_button.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="300dp"
android:weightSum="1">
<TextView
android:id="@+id/textView2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="0.05"
android:background="@color/colorAccent"
android:gravity="center"
android:text="7"
android:textAlignment="center"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/textView7"
android:clickable = "true"/>
<TextView
android:id="@+id/textView1"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="8"
android:textAlignment="center"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/textView2"
android:clickable = "true"/>
<TextView
android:id="@+id/textView3"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="9"
android:textAlignment="center"
android:layout_toEndOf="@+id/textView1"
android:layout_above="@+id/textView5"
android:clickable = "true"/>
<TextView
android:id="@+id/textViewC"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="C"
android:textAlignment="center"
android:layout_below="@+id/textView8"
android:layout_toEndOf="@+id/textView3"
android:clickable = "true"/>
<TextView
android:id="@+id/textView4"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="4"
android:textAlignment="center"
android:layout_below="@+id/textView2"
android:layout_toEndOf="@+id/textView7"
android:clickable = "true"/>
<TextView
android:id="@+id/textView5"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="5"
android:textAlignment="center"
android:clickable = "true"
android:layout_below="@+id/textView1"
android:layout_toEndOf="@+id/textView2" />
<TextView
android:id="@+id/textView6"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="6"
android:textAlignment="center"
android:layout_above="@+id/textViewiki"
android:layout_alignEnd="@+id/textViewüç"
android:clickable = "true"/>
<TextView
android:id="@+id/bölme"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="/"
android:textAlignment="center"
android:layout_above="@+id/textViewüç"
android:layout_alignEnd="@+id/textViewC"
android:clickable = "true"/>
<TextView
android:id="@+id/textbir"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="1"
android:textAlignment="center"
android:layout_alignBottom="@+id/textViewiki"
android:clickable = "true"/>
<TextView
android:id="@+id/textViewiki"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="2"
android:textAlignment="center"
android:layout_below="@+id/textView5"
android:layout_toEndOf="@+id/textbir"
android:clickable = "true"/>
<TextView
android:id="@+id/textViewüç"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="3"
android:textAlignment="center"
android:layout_below="@+id/textView6"
android:layout_toEndOf="@+id/textView5"
android:clickable = "true"/>
<TextView
android:id="@+id/textViewyıldız"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="*"
android:textAlignment="center"
android:layout_below="@+id/bölme"
android:layout_toEndOf="@+id/textView6"
android:clickable = "true"/>
<TextView
android:id="@+id/textView0"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="0"
android:textAlignment="center"
android:layout_below="@+id/textbir"
android:layout_toEndOf="@+id/textView7"
android:clickable = "true"/>
<TextView
android:id="@+id/textVieweşit"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="="
android:textAlignment="center"
android:layout_toEndOf="@+id/textView0"
android:layout_alignBottom="@+id/textView0"
android:clickable = "true"/>
<TextView
android:id="@+id/cıkar"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="-"
android:textAlignment="center"
android:layout_toEndOf="@+id/textView3"
android:layout_alignBottom="@+id/textView0"
android:clickable = "true"/>
<TextView
android:id="@+id/topla"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="+"
android:textAlignment="center"
android:layout_alignBottom="@+id/textVieweşit"
android:layout_toStartOf="@+id/cıkar"
android:clickable = "true"/>
</RelativeLayout>
38
Görüntülenme
0 Beğeni